package org.example.product.controller;

import com.example.api.ProductInterface;
import com.example.module.ProductInfo;
import org.example.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController implements ProductInterface {
    @Autowired
    private ProductService productService;
    @RequestMapping("/{productId}")
    public ProductInfo getProductById(@PathVariable("productId") Integer productId) {
        return productService.findProductInfo(productId);
    }

    @RequestMapping("/p1")
    public String p1(Integer id) {
        return "p1 接收到参数: " + id;
    }

    @RequestMapping("/p2")
    public String p2(Integer id, String name) {
        return "p2 接收到参数: id: " + id + " name: " + name;
    }

    @Override
    public String p3(ProductInfo productInfo) {
        return "p3 接收到对象, productInfo: " + productInfo;
    }

    @Override
    public String p4(ProductInfo productInfo) {
        return "p4 接收到 JSON, productInfo: " + productInfo;
    }

}
